//账单记录
$(function () {
    var token = sessionStorage.getItem("token");
    var method = "order|order_list";
    var pagesize = "6";
    var mid = $(".xq").attr("data-id");
    var p = 1;
    var i = 1;
    //                if(mid=="mx"){
    //                    xqMore();
    //                    $(".More").click(function(){
    //                            p+=1;
    //                            $(this).attr("disabled","disabled");
    //                            setTimeout(function(){
    //                                    $(".More").removeAttr("disabled");
    //                            },2000);
    //                            
    //                            xqMore(p);
    //                    })
    //                }else{
    zdMore(p);
    $(".More").click(function () {
        p += 1;
        var type = $(this).attr("data-type");
        $(this).attr("disabled", "disabled");
        setTimeout(function () {
            $(".More").removeAttr("disabled");
        }, 2000);
        zdMore(p, type);
    })
    //                }


    $("#to-sx").click(function () {
        i++;
        if (i % 2 == 0) {
            $("#sx").show();
            var d = {};
            d.token = token;
            d.method = "Order|get_type";
            $.ajax({
                type: "post",
                url: "http://www.rice.com/app/api/h5_access",
                data: d,
                dataType: "json",
                success: function (result) {
                    if (result.status == "1") {
                        var sttr = "";
                        var data = result.data;
                        for (var i in data) {
                            sttr += '<li style="cursor:pointer;" onclick="javascript:sxClick(this);" data-type="' + data[i].type + '"><span>' + data[i].name + '</span></li>';
                        }
                        $("#sx").html(sttr);

                    }

                }
            })
        } else {
            $("#sx").hide();
        }

    })

    function xqMore(p) {
        if (!p) {
            p = 1;
        }
        var d = {};
        d.token = token;
        d.method = method;
        d.p = p;
        d.pagesize = pagesize;
        $.ajax({
            type: "post",
            url: "http://www.rice.com/app/api/h5_access",
            data: d,
            dataType: "json",
            success: function (result) {
                if (result.status == "1") {
                    var data = result.data.data;
                    var sttr = $(".xq").html();
                    for (var i in data) {
                        var hh = data[i].add_time;
                        var date = new Date(hh * 1000);
                        var Y = date.getFullYear() + '-';
                        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                        var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
                        var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
                        var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
                        var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());

                        sttr += '<div style="position: relative;padding: 10px;padding-bottom:0;cursor: pointer;" class="tmx" data-id="' + data[i].order_id + '">';
                        sttr += ' <img src="img/order_detail_bg_img.png"  width="100%" />';
                        sttr += '<div style="position: absolute;z-index: 100;top: 23%;left: 24%;"><span style="font-size: 16px; color: #fff;">' + data[i].type_name + '¥ ' + data[i].amount + '</span></div>';
                        sttr += '<div style="position: absolute;z-index: 100;top: 23%;left: 83%;"><span style="font-size: 16px; color: #fff;">删除</span></div>';
                        sttr += '<div style="position: absolute;z-index: 100;top: 62%;left: 24%;"><span style="font-size: 13px; color: #fff;">' + Y + M + D + h + m + s + '尾号(' + data[i].bank_no + ')</span></div>';
                        sttr += '<div style="position: absolute;z-index: 100;top: 45%;left: 76%;"><span style="font-size: 16px; color: #fff;">' + data[i].status_name + '</span></div>';
                        sttr += '</div>';
                    }
                    $(".xq").html(sttr);
                    $(".tmx").click(function () {
                        var order_id = $(this).attr("data-id");
                        sessionStorage.setItem("order_id", order_id);
                        location.href = "bill1.html";
                    })
                } else if (result.status == "2") {
                    alert(result.message);
                    location.href = "login.html";
                } else {
                    alert(result.message);
                }
            }
        });
    }


    //账单
    function zdMore(p, t) {
        if (!p) {
            p = 1;
        }
        var d = {};
        d.token = token;
        d.method = "order|order_list";
        d.p = p;
        d.pagesize = pagesize;
        d.type = t;
        $.ajax({
            type: "post",
            url: "http://www.rice.com/app/api/h5_access",
            data: d,
            dataType: "json",
            success: function (result) {
                if (result.status == "1") {
                    var data = result.data.order_data;
                    var sttr = $(".xq").html();
                    for (var i in data) {
                        var hh = data[i].add_time;
                        var date = new Date(hh * 1000);
                        var Y = date.getFullYear() + '-';
                        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                        var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
                        var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
                        var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
                        var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());

                        sttr += '<div style="position: relative;padding: 10px;padding-bottom:0;cursor: pointer;" class="tmx" data-id="' + data[i].order_id + '">';
                        sttr += ' <img src="img/order_detail_bg_img.png"  width="100%" />';
                        sttr += '<div style="position: absolute;z-index: 100;top: 23%;left: 24%;"><span style="font-size: 16px; color: #fff;">' + data[i].type_name + '¥ ' + data[i].amount + '</span></div>';
                        sttr += '<div style="position: absolute;z-index: 100;top: 23%;left: 83%;"><span style="font-size: 16px; color: #fff;">删除</span></div>';
                        sttr += '<div style="position: absolute;z-index: 100;top: 62%;left: 24%;"><span style="font-size: 13px; color: #fff;">' + Y + M + D + h + m + s + '尾号(' + data[i].bank_no + ')</span></div>';
                        sttr += '<div style="position: absolute;z-index: 100;top: 45%;left: 76%;"><span style="font-size: 16px; color: #fff;">' + data[i].status_name + '</span></div>';
                        sttr += '</div>';

                    }
                    $(".xq").html(sttr);
                    $(".tmx").click(function () {
                        var order_id = $(this).attr("data-id");
                        sessionStorage.setItem("order_id", order_id);
                        location.href = "bill1.html";
                    })
                } else if (result.status == "2") {
                    alert(result.message);
                    location.href = "login.html";
                } else {
                    alert(result.message);
                }
            }
        });
    }
})
var token = sessionStorage.getItem("token");
var method = "gathering";
var pagesize = "6";

function sxClick(obj) {
    var type = $(obj).attr("data-type");
    $('.More').attr("data-type", type);
    zdmore(1, type);
};

function zdmore(p, t) {
    var d = {};
    d.token = token;
    d.method = "order|order_list";
    d.p = p;
    d.pagesize = pagesize;
    d.type = t;
    $.ajax({
        type: "post",
        url: "http://www.rice.com/app/api/h5_access",
        data: d,
        dataType: "json",
        success: function (result) {
            if (result.status == "1") {
                var data = result.data.order_data;
                var sttr = "";
                for (var i in data) {
                    var hh = data[i].add_time;
                    var date = new Date(hh * 1000);
                    var Y = date.getFullYear() + '-';
                    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
                    var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
                    var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
                    var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
                    sttr += '<div style="position: relative;padding: 10px;padding-bottom:0;cursor: pointer;" class="tmx" data-id="' + data[i].order_id + '">';
                    sttr += ' <img src="img/order_detail_bg_img.png"  width="100%" />';
                    sttr += '<div style="position: absolute;z-index: 100;top: 23%;left: 24%;"><span style="font-size: 16px; color: #fff;">' + data[i].type_name + '¥ ' + data[i].amount + '</span></div>';
                    sttr += '<div style="position: absolute;z-index: 100;top: 23%;left: 83%;"><span style="font-size: 16px; color: #fff;">删除</span></div>';
                    sttr += '<div style="position: absolute;z-index: 100;top: 62%;left: 24%;"><span style="font-size: 13px; color: #fff;">' + Y + M + D + h + m + s + '尾号(--)</span></div>';
                    sttr += '<div style="position: absolute;z-index: 100;top: 57%;left: 76%;"><span style="font-size: 16px; color: #fff;">' + data[i].status_name + '</span></div>';
                    sttr += '</div>';
                }
                $(".xq").html(sttr);
                $(".tmx").click(function () {
                    var order_id = $(this).attr("data-id");
                    sessionStorage.setItem("order_id", order_id);
                    location.href = "bill1.html";
                })
            } else if (result.status == "2") {
                alert(result.message);
                location.href = "login.html";
            } else {
                alert(result.message);
            }
        }
    });
}